/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.*;;
/**
 *
 * @author me
 */
public class IOHelper {
    public static void saveObject(Object obj, String filename) throws Exception
    {
        ObjectOutputStream outputStream = null;

        try {
            //Construct the LineNumberReader object
            outputStream = new ObjectOutputStream(new FileOutputStream(filename));
            outputStream.writeObject(obj);
        } catch (Exception ex) {
            ex.printStackTrace();
            if (outputStream != null) {
                outputStream.flush();
                outputStream.close();
            }
            throw ex;
        }
    }


    public static Object loadObject( String filename) throws Exception {
        ObjectInputStream inputStream = null;
        Object obj = null;
        try {
            inputStream = new ObjectInputStream(new FileInputStream(filename));
            obj = inputStream.readObject();
        } catch(Exception ex) {
            ex.printStackTrace();
            if (inputStream != null) {
                inputStream.close();
            }
            throw ex;
        }
        return obj;
    }

    public static void main(String[] args) throws Exception {
        IOHelper.saveObject("123", "C:\\1.txt");
        Profile profile = new Profile();
        IOHelper.saveObject(profile, "C:\\2.txt");
    }
}
